package com.ruoyi.app.api

import com.drake.net.request.MediaConst.JSON
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody

object OKHttpUtils  {

    fun <T> getRequestBody(result: T): RequestBody {
        if (result == null) {
            return getRequestBody("")
        }
        val jsonString = MoshiConverter.moshi.adapter<T>(result!!::class.java)
            .toJson(result)
        return getRequestBody(jsonString);
    }

    private fun getRequestBody(result: String): RequestBody {
        return result.toRequestBody(JSON);
    }

}
